package br.ufrgs.meetappsoapserver;

import java.util.ArrayList;

import javax.jws.WebMethod;
import javax.jws.WebService;

import model.Meeting;
import model.User;

@WebService
public class Server {
	
	private ArrayList<Meeting> meetings = new ArrayList<>();

	@WebMethod
	public void createMeeting(String meetingAsString){
		//TODO parse meeting string
		
		Meeting newMeeting = new Meeting();
		
		meetings.add(newMeeting);
		
	}
	
	@WebMethod
	public String update(String userAsString){
		String response = "";
		
		//TODO parse user
		String[] userInfo = userAsString.split("");
		
		User user = new User();
		//TODO search user in meetings
		for (Meeting meeting : meetings) {
			for (User existingUser : meeting.getUsers()) {
				if(user.getEmail().equals(existingUser.getEmail())){
					existingUser.setCurrentLat(user.getCurrentLat());
					existingUser.setCurrentLong(user.getCurrentLong());
					response = meeting.toString();
					break;
				}
			}
			//user found and response set, exit for
			if(! "".equals(response)){
				break;
			}
		}
		
		return response;
	}
}
